package com.why.blog.front.bolg;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.why.blog.common.R;
import com.why.blog.entity.HaloComment;
import com.why.blog.entity.VO.CommentVO;
import com.why.blog.service.CommentService;
import com.why.blog.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author TriggerWu
 * @version 1.0.0
 * @ClassName BlogController.java
 * @Description 前端博客文章管理
 * @createTime 2019年05月08日 16:28:00
 */
@RestController
@RequestMapping("/front")
public class BlogController {

    @Autowired
    private PostService postService;

    @Autowired
    private CommentService commentService;



    @GetMapping("/blog/{postId}")
    public R postInfo(@PathVariable("postId") String postId) {
        return postService.showPostVo(postId);
    }

    @GetMapping("/comment/{poId}")
    public IPage<HaloComment> commentList(@PathVariable("poId") String postId, @RequestParam(value = "page", defaultValue = "1") Integer page,
                                          @RequestParam(value = "limit", defaultValue = "10") Integer pageSize) {
        CommentVO co = new CommentVO();
        co.setPostId(postId);
        return commentService.showList(co, page, pageSize);
    }

    @GetMapping("/blog/postIndex")
    public R blogindex(@RequestParam(value = "page", defaultValue = "1") Integer page,
                       @RequestParam(value = "limit", defaultValue = "10") Integer pageSize,
                       @RequestParam(value = "categoryId" ,required = false) Integer categoryId){

        return postService.blogIndex(page,pageSize,categoryId);
    }

    @GetMapping("/tagCount")
    public R tagsCount(@RequestParam("tagId") Integer tagId){
        return postService.querytagsCount(tagId);
    }

    @GetMapping("/showTagList")
    public R taglist(@RequestParam(value = "page", defaultValue = "1") Integer page,
                     @RequestParam(value = "limit", defaultValue = "10") Integer pageSize,
                     @RequestParam(value = "tagId" ,required = false) Integer tagId){
        return postService.selectTag(tagId,page,pageSize);
    }

}
